<template>
  <el-dialog v-el-drag-dialog custom-class="add-eidt-personal-dialog" :visible.sync="value" :close-on-click-modal="false"
             :before-close="close" width="60%">
    <div slot="title" class="text-l dd pt15 pb15 pr20 pl20">
      <span class="bold">{{ title }}<el-button class="ml10" type="success" @click="getTemplate()" :loading="loading">刷新列表</el-button></span>
    </div>
    <div style="width: 100%; height: 100%; box-sizing: border-box" class="flex-c">
      <div class="flex1">
        <el-table :data="templateList" border class="wp100" empty-text="暂无相关数据">

          <el-table-column label="ID" width="70" prop="TID">

          </el-table-column>

          <el-table-column label="同意书名称" prop="MC">
            <template slot-scope="scope">
              <el-link type="default" @click="selectTemp(scope.row)">{{ scope.row.MC }}</el-link>
            </template>
          </el-table-column>

          <el-table-column v-for="item in headers" :key="item.prop" :prop="item.prop" :label="item.label"
                           :width="item.width">
          </el-table-column>
          <el-table-column label="操作" width="80">
            <template slot-scope="scope">
              <el-button type="primary" @click="selectTemp(scope.row)">添加</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </el-dialog>
</template>
<script>
import elDragDialog from "@/modules/CST/directive/el-dragDialog";
import { CONSENT_GET_TEMPLATE_LIST } from "_SERVICES/api";
import { simDeepCopy, getStorage, setStorage } from "UTILS/util";

export default {
  model: {
    event: "change",
  },
  directives: { elDragDialog },
  props: {
    ZKID: {
      required: true,
    },
    value: {
      required: true,
    },
    title: {
      required: true,
    },
  },
  data() {
    return {
      templateList: [],
      headers: [
        // {
        //   label: "ID",
        //   prop: "TID",
        //   width:70
        // },
        // {
        //   label: "同意书名称",
        //   prop: "MC",
        // },
        {
          label: "归属科室",
          prop: "ZKMC",
        },
        {
          label: "排序",
          prop: "PX",
          width: 70
        },
        {
          label: "新增时间",
          prop: "XZSJ",
          width: 150
        },
      ],
      loading: false

    };
  },
  created() {
    this.getTemplate();
  },
  watch: {
    ZKID: {
      handler(val) { },
      immediate: true,
    },
  },
  methods: {
    getTemplate() {

      let userInfo = getStorage("cst_userInfo");
      if (userInfo) {
        userInfo = JSON.parse(userInfo);
      } else {
        userInfo = {}
      }

      let obj = {
        ZTBZ: 2,
        download: 1
      }

      //为了便于调试 管理员可以使用所有的模板进行调试
      if (userInfo.ROLE_ID.includes("1")) {
        delete obj.ZTBZ;
      }
      this.loading = true;

      CONSENT_GET_TEMPLATE_LIST(obj).then((res) => {
        console.log("获取已发布模板1")
        this.templateList = res.data || [];
        this.loading = false;
      }).catch((e)=>{
        this.loading = false;
      });
    },
    close() {
      this.$emit("cancelFun", 0);
    },
    selectTemp(row) {
      this.$emit("submitFun", row);
    },
  },
};
</script>
<style lang="less">
.add-eidt-personal-dialog {
  width: 60%;
  height: 70%;
  box-sizing: border-box;

  display: -webkit-flex;
  /* Safari */
  display: flex;
  flex-direction: column;

  .el-dialog__header {
    padding: 0px;
  }

  .el-dialog__body {
    -webkit-box-flex: 1;
    flex: 1;
    overflow-y: auto;
    box-sizing: border-box;
    padding: 10px 20px;
  }
}
</style>



